package main

import (
	"fmt"
	"sort"
	"time"
)

// [bottom,top]  special[i]用于放松
func maxConsecutive(bottom int, top int, special []int) int {
	max := 0
	sort.Slice(special, func(i, j int) bool {
		return special[i] < special[j]
	})
	// q := []int{}
	// for _,spec:=range special {
	// 	q = append(q, spec)
	// }
	// special 将数组分段
	lastStart := bottom
	for i:=0;i<len(special);i++{
		length := special[i] - lastStart
		if length > max {
			max = length
		}
		lastStart = special[i] + 1
	}
	// top - lastStart
	length := top - lastStart + 1
	if length > max {
		max = length
	}
	return max
	// for i := bottom; i <= top; i++ {
	// 	// 和队头比
	// 	if len(q) == 0 {
	// 		left := top - i +1
	// 		if left > max {
	// 			return left
	// 		}else{
	// 			return max
	// 		}
	// 	}
	// 	top := q[0]
	// 	q = q[1:]
	// 	var cnt int
	// 	for i<=top && i!=top {
	// 		i++
	// 		cnt++
	// 	}

	// 	if cnt>max{
	// 		max=cnt
	// 	}
	// }
	// return max
}

func main() {
// 	bottom,top:= 197570,999896340
// special := []int{176281845,539966173,805135536,886060576,424325063,440336240,257224409,627256568,634910644,706552839,565532305,58021427,609001797,82338045,483990535,346637040,650708016,543400707,145463543,753998477,658496247,23479100,170476534,172131594,979632501,428941147,536632143,368039304,127863429,520257391,320242848,779745795,971044384,817272073,171422140,419984079,654170088,206694932,299836168,818693247,259845697,739193699,308512247,909926529,726795371,783861082,903003793,498472155,570043796,872183492,286738312,95397401,524986144,81171439,458033189,265561949,353572121,971745101,474887300,21225410,860652618,350677591,346506517,352503567,959265990,21653412,607557775,819193852,934274318,447406233,13259397,981958179,51323876,262909581,480647977,184182774,788652531,851161491,922538598,67213946,813834516,521798795,4366174,120235243,570423839,193549790,360037172,215920037,457806668,40535797,769930249,701016955,967957098,584027596,622901515,631223557,695312373,786431338,382705216,241022697,52298991,470152537,567384451,598955929,396907099,151661261,252102047,864415309,605879600,286292390,405914964,803980776,497912492,781215570,218493241,895654606,225586414,656083650,206818375,704267384,191519436,450391524,263011726,628678909,493552153,875932789,186971728,100322806,529844157,429962100,735906789,482226747,880723048,591089968,338936963,700733711,967232826,401810165,392921856,947781115,113559173,544709781,825612734,982191522,116199277,687290833,274243674,233175187,855395984,352076732,812303685,649893608,7133394,925516798,494527958,168319921,727941294,931363516,593743413,956009792,481123371,373802169,850935121,916177163,276709175,362680472,600445853,663556756,340008633,520248579,655093489,496997429,92802976,197130128,607995754,381125652,557991165,542881723,678475415,802940578,375506146,273022435,813582747,127484994,531505163,639025495,546869663,265120405,491336562,198912661,263264343,420160543,719268202,935247869,722263966,773901892,188309428,297405061,958002202,939288596,761813344,420912858,90188558,727877739,353700420,432105874,567652647,996994529,955780204,769202212,428972112,303518019,512510740,806339399,363284557,967427407,270253432,843819501,817366530,630292419,299747060,40644061,649517466,96939299,744578142,432323974,797310804,511664973,653779189,524177812,248688823,424716344,450673063,364724725,268269259,635705522,550840944,575028535,357913062,893286026,805440397,197494076,476146140,833424871,484117678,556055921,177934035,7010462,385884707,285231433,937118230,814432735,168209595,23246765,811837841,822447283,524962310,492559960,31913014,383251584,388852569,456935783,713330250,341632935,320331231,811076902,918089574,950256438,811812944,282106364,567062467,215908833,702918444,727828300,446766496,740534638,997284885,99489385,899907158,57388374,881267048,358648607,209534231,145500793,760913439,7971388,314660386,153767504,548418455,302142523,722355489,832847533,254090606,878032338,151392896,15549234,819882236,873910642,586223947,982019640,441053764,369654094,422492332,13903252,360624469,302016571,553742457,178443082,47904190,393494107,690230102,340634040,679593960,607786276,572918436,788273580,438575916,566621223,710624072,658554064,235195993,762291218,546982305,979477097,856361251,884178856,397616439,468754766,571740655,638023795,67025110,849882384,910841283,278825807,814755308,673225,212314757,871021001,321513913,674959930,862733904,727180655,357582016,461087185,571733781,300814285,292533515,661173531,785192132,514078451,698781931,357015553,569487667,807338481,569732772,609190141,360538847,88863088,454908740,30823842,493917572,586839572,904201887,105635761,761046376,423491457,639591501,794987860,947928804,18869973,493737960,232926581,569414101,425047356,336761861,408132479,232674600,581694317,194539474,831465454,441050022,238320112,272528917,941100666,281920620,699854022,782492224,644886572,226441267,262743717,629065805,312709642,607296648,313617083,41241329,895716543,677957489,485024746,243036279,349264083,806042891,159849993,301499001,657489989,393968438,221136252,276489711,831144776,676048415,547660345,182717654,17665427,870798893,970954080,747241861,546111419,909727593,922001812,757746658,387992538,567657984,717874529,225122292,261646609,943841165,275479347,736312656,949639411,729986901,691143348,35578065,432893965,187978499,298571230,82164976,272867369,737340439,858462162,746189183,837251236,772201654,408194393,641128871,881412328,143771441,285364119,242709606,791814760,686542911,817847746,298291478,224488065,726517752,117741558,26710157,354342499,597232396,705893317,25621651,503367740,98038119,799799788,715320271,100636802,948141966,382824149,117321753,354053167,696496009,453564962,916286558,448707668,263482734,662112564,311826452,964771215,443940676,807081344,296039215,772994203,959349966,26003280,728658682,254107539,93956349,166100702,568230256,299539715,504316543,137499228,810198765,395441762,360965841,584863098,535884675,96141671,789936474,295351955,827287389,205019401,540763792,870019393,720525330,317212734,487883803,388720278,396570190,986907710,792750753,878557523,548318055,629016078,334388332,176765107,344908111,952792144,259189089,694964038,33616703,564060824,641641316,188316163,36733217,551641294,402635096,891002489,443377265,67528485,888522745,534144450,451542743,199013909,158555426,739445416,251250400,97778872,767209729,695698400,4017491,513265693,433925338,424140751,61333171,775194766,500283973,682876735,752885258,298314029,990990850,847007702,72642974,995392852,43493039,980551296,53674903,269642575,500255279,329665175,380534528,50374169,943020568,952269575,600584043,984559892,725031255,114697967,910136693,609287634,491407356,299688713,909835152,805759970,373318586,515219983,478666764,523342574,364266242,666285899,775139525,486281568,560711435,270866001,842026308,966272405,951857426,840372966,559521852,339382959,454418997,904819126,706707415,762877855,47940071,142275373,821294249,103768048,359518978,410265307,891972854,66623557,900484805,26513919,579495932,902615165,735037270,88413811,887334700,417581096,67155652,646465055,517119524,582264718,548592614,925040701,742616493,950972085,621019063,982359975,197084683,520813442,999784830,14098322,568893107,973965208,163473277,546442223,973834474,372732566,171741762,263757766,735278902,599319165,592217543,543632363,141019430,958178076,556456461,905016822,238442006,819656426,109097179,140766724,927229276,775595905,703417550,910982004,883428733,659894670,780448975,863248136,4571896,312605210,951365941,666707076,380727630,807194445,723644663,598404368,934292689,981211737,106579976,249402061,40035442,294985217,867306752,80127555,218912095,602907331,876152488,84379449,386765933,277139868,532483662,157839208,499478644,852762092,594034427,347094735,918922328,188586697,369062230,310218448,248465651,594578679,146305363,921334312,762393271,737293316,825781411,524202739,948624983,89565902,143003037,436763746,496477446,776780062,567501363,84879483,169883643,442551025,756106383,827951746,118368606,490429542,995617536,87925501,296523335,558652638,556561647,812148925,369185252,395277355,326775835,245983564,296651076,238587991,198651816,343088108,63458343,763770150,562802760,317976254,485331329,463124694,805913542,232170614,650409236,804304748,541056233,668879520,367585231,368489278,459835240,807845222,331911125,262426974,54552456,664200680,534341623,52318782,646485569,601478325,882030448,549779659,718210540,143745316,128907073,773762503,156104453,466709504,88969423,242366522,118255105,416925273,60064035,295547724,235102861,659313733,61524896,406465009,274237125,981759546,539359594,198460540,332019470,842663577,990125744,762574433,42125050,124425271,948649097,125756356,925507040,15993334,475716097,780182336,981690178,80141848,926568929,49578636,735807145,511489079,410186381,590511549,478368508,597525890,517024635,630251591,586275644,281668622,507114775,832455055,925153866,127838903,645209957,663388898,696045467,963582121,901199025,30348898,645675149,442771084,246854400,813793,405163122,533728137,796987394,38214810,16060265,601705112,635115785,92074262,653193290,798804132,828787281,367445755,355451264,151177276,753174447,14171269,90772213,510867775,106859226,35212138,105057225,563361852,109992771,756610207,400295530,862996952,813071433,400438276,785935168,363095319,97979082,578144905,922328105,736232497,857374052,777339263,949164911,753590032,492897158,489017345,904285656,93574480,53625446,379928204,434864351,388851128,850114397,283755812,590588812,602985201,866043242,823668904,885775789,578336948,217906056,670111640,105149455,557244348,474090672,413952928,964066238,388169895,238422388,879263356,280563925,334411713,566098105,197775651,315156371,456949197,227745557,551970562,237407163,399305666,573662931,924870166,155098411,18559663,766239502,811563826,519827519,322746297,293796111,83268980,321151015,253035470,307067276,684664518,757054669,206562146,701259654,617521478,844797820,80512501,472232207,360406009,288222940,95180768,518494184,756530877,141812296,870952063,811942640,404713291,727644687,550627726,434593258,239186248,5281180,247068048,637937540,397356682,242412607,893503793,837220391,211796651,708542171,900968591,19150900,108677997,748020771,362175705,672371895,992821302,291153646,710674350,641163208,54742107,141080924,343217879,216739632,913425625,91804813,167472696,282977687,293428467,590674111,32664218,978010384,53601295,857260177,559293693,551998465,60395395,732633394,788644741,445404110,751043478,34732243,647104639,31529412,33780972,650298781,349046199,78670156,364426240,866959002,70129212,887993367,715098938,985919765,540986169,198777080,958206185,122856513,215575510,700963312,792083000,494041641,489149665,653099192,615977159,905803118,814214080,273985478,289490489,467995514,852705840,491570417,758290070,388542849,108271152,951396326,82337853,438819509,556389287,417144808,771338901,116755690,897840554,768150156,532790551,986335239,859352897,603432189,936336344,659537457,233610101,963440439,206727238,322364312,947782524,137442475,475729416,506741785,
// 	138435812,462439292,928813690,284676231,329809197,436144065,738352513,944996518,73684934,806282579,253149931,353568734,148731026,853107020,49905001,695827939,342596954,717726006,664392518,859126102,488491942,668373973,569318152,846518916,734533644,317970701,230497196,270025364,953998701,667822355,11067178}
// 	
	bottom,top,special := 2,9,[]int{4,6}
	startTime := time.Now()
	res := maxConsecutive(bottom,top,special)
	endTime := time.Now()
	dur := endTime.Sub(startTime).Milliseconds()
	fmt.Println(dur)
	fmt.Println(res)
}